<template>
  <div class="LevelPage">
    <div class="filter-container search_Top">
      <div class="search_input_list">
        <div class="filter-item">
          <el-input clearable  v-model="queryParam.itemName" placeholder="等级名称"
                    size="mini"
                    @keyup.enter.native="getList" />
        </div>
        <div class="filter-item">
          <el-input clearable  v-model="queryParam.serialNo" placeholder="等级代码"
                    size="mini"
                    @keyup.enter.native="getList" />
        </div>
      </div>
      <div class="filter-item filter-item-btn-search search_bt_list">
        <span class="gosearch" @click="getList">搜索</span>
        <span class="clears" @click="clearList">清除</span>
      </div>
    </div>

    <div class="table_base_bt">
      <el-button class="filter-btn-item" v-if="hasRole('param:basedata:add')"
                    size="mini"
                    type="primary"
                    icon="el-icon-edit"
                    @click="handleCreate">新增</el-button>
    </div>

    <drug-table :tableData="tableData"  @getSelection="getSelection" :isMultipleSelection="true" :pageSizeParam="pageSizeParam" :tableLoading="tableLoading" :tableHeader="tableHeader" :option="option">
        <template slot-scope="props" slot="operate">
          <div v-if="hasRole('param:basedata:del')">
            <label @click="handleDelete(props.rowData)" class="table-view">
                删除
            </label>
          </div>
        </template>
      </drug-table>
    <level-edit :editData="levelDetail" :type="operateType" :existLogin="tableData" ></level-edit>
  </div>
</template>

<script>
import drugTable from "@/components/table/index";
import levelEdit from "./edit.vue";

export default {
  components: { drugTable,levelEdit },
  data() {
    return {
      tableData: [],
      tableHeader:[],
      tableLoading:true,
      option:{showOperate:true},
      selectChoice:[],
      levelDetail:{},
      operateType:"add",
      queryParam:{serialNo:"",itemName:"",itemCode:"grade"},
      pageSizeParam:20
    }
  },
  mounted() {
    let self = this;
    self.$eventBus.$on("updateLevelObj",function () {
      self.queryParam = {serialNo:"",itemName:"",itemCode:"grade"};
      self.getList()
    });
    self.getList()
  },
  methods: {
    handleCreate(){
      this.levelDetail = {serialNo:"",itemName:"",itemCode:"grade"};
      this.operateType = "add";
    },
    getSelection(val){
      this.selectChoice = val;
    },
    getList() {
      let self = this;
        self.tableLoading = true;
        self.$http({
          url: "/drug/codeItem/queryCodeItemList",
          method: "post",
          params: self.queryParam
        }).then(resp => {
          if (resp.success) {
            self.pageSizeParam = 10;
            self.tableLoading = false;
            self.tableData = resp.result;
            self.tableHeader = [
              {"columnName": "itemName", "coloumNameCn": "等级名称"},
              {"columnName": "serialNo", "coloumNameCn": "等级代码"},
              {"columnName": "createTimeFt", "coloumNameCn": "创建日期", "width": "150px"},
              {"columnName": "userName", "coloumNameCn": "创建人", "width": "150px"},];
            self.option.showOperate = true;
          }
        });
    },
    handleDelete(rowData) {
      let self = this;
      let param = {id: rowData.id, status: "-1"};
      self.$confirm('确定删除该信息？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        self.$http({
        url: "/drug/codeItem/updateCodeItem",
        method: "post",
        params: param
        }).then(resp => {
        self.getList();
        self.$notify({
            title: '提示',
            message: '删除成功',
            type: 'success',
            duration: 1000
        });
        });
      });
    },
    clearList() {
      let self = this;
      self.queryParam = {serialNo:"",itemName:""};
      self.getList()
    },
  },
}
</script>

<style lang="scss" scoped>

</style>
